﻿@using LiUTrading.MvcHelpers
@model IEnumerable<LiUTrading.Models.Ad>
@{
    ViewBag.Title = "MyAds";
}
<table>
    <thead>
        <tr>
            <th>
                Time added
            </th>
            <th>
                Title
            </th>
            <th>
                Category
            </th>
            <th>
                Price
            </th>
            <th>
                Edit
            </th>
            <th>
                Details
            </th>
            <th>
                Delete
            </th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.DateTime)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Title)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Category)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Price)
                </td>
                <td>
                    @Html.DialogFormLink("Edit Ad", Url.Action("Edit", new { id = item.AdId }), "EditAd", "Edit Ad", "dialog", Url.Action("MyPage", "Account"))
                </td>
                <td>
                    <div class="addetails">
                        <button class="addetails" id="detailsopener" data-addetailsid="@item.AdId">
                            Show Details</button>
                    </div>
                </td>
                <td>
                    <div class="delete">
                        <button class="delete" id="deleteopener" data-addeleteid="@item.AdId">
                            Delete Ad</button>
                    </div>
                </td>
            </tr>
        
        }
    </tbody>
</table>
<script type="text/javascript">

    var oAdId;
    $(function () {
        $('#dialog-confirm').dialog({
            autoOpen: false,
            width: 400,
            resizable: false,
            title: 'Delete Ad',
            modal: true,

            open: function (event, ui) {

                $(this).load('@Url.Action("Delete", "Ads")', { id: oAdId });
            },
            buttons: {
                "Delete Ad": function () {
                    location.reload(true);
                    $(this).load('@Url.Action("DeleteConfirm", "Ads")', { id: oAdId, confirmButton: "true" });
                    $(this).dialog("close");
                    return false;
                },
                "Close": function () {
                    $(this).dialog("close");
                    return false;
                }
            }
        });

        $('.delete').click(function () {
            oAdId = $(this).attr('data-addeleteid');
            $('#dialog-confirm').dialog('open');
            $('#dialog-confirm').dialog("option", "position", "top");
            return false;
        });
    });
</script>
<div id="dialog-confirm" title="Delete Ad" style="overflow: hidden;">
</div>
